import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
var _excluded = ["organizationId"];
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
/**
 * 查询公司信息
 * @param {Object} params - 查询参数
 * @param {String} params.organizationId - 组织ID
 */

export function fetchCompany(_x) {
  return _fetchCompany.apply(this, arguments);
}
/**
 * 设置公司启用
 * @param {Object} params - 查询参数
 * @param {String} params.organizationId - 组织ID
 */

function _fetchCompany() {
  _fetchCompany = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var organizationId, other;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            organizationId = params.organizationId, other = _objectWithoutProperties(params, _excluded);
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/companies"), {
              method: 'GET',
              query: other
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchCompany.apply(this, arguments);
}

export function enableCompany(_x2) {
  return _enableCompany.apply(this, arguments);
}
/**
 * 设置公司禁用
 * @param {Object} params - 查询参数
 * @param {String} params.organizationId - 组织ID
 */

function _enableCompany() {
  _enableCompany = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var organizationId;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/companies/enable"), {
              method: 'POST',
              body: params.body
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _enableCompany.apply(this, arguments);
}

export function disableCompany(_x3) {
  return _disableCompany.apply(this, arguments);
}
/**
 * 查询单条公司信息
 * @param {Object} params - 查询参数
 * @param {String} params.organizationId - 租户ID
 * @param {String} params.companyId - 公司ID
 */

function _disableCompany() {
  _disableCompany = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    var organizationId;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/companies/disable"), {
              method: 'POST',
              body: params.body
            }));

          case 2:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _disableCompany.apply(this, arguments);
}

export function queryCompany(_x4) {
  return _queryCompany.apply(this, arguments);
}
/**
 * 新建公司
 * @param {Object} params - 查询参数
 */

function _queryCompany() {
  _queryCompany = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.organizationId, "/companies/").concat(params.companyId), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _queryCompany.apply(this, arguments);
}

export function createCompany(_x5) {
  return _createCompany.apply(this, arguments);
}
/**
 * 查询国家地区.
 * @param {Number} countryId 国家ID
 * @export
 */

function _createCompany() {
  _createCompany = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.tenantId, "/companies"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _createCompany.apply(this, arguments);
}

export function queryProvinceCity(_x6) {
  return _queryProvinceCity.apply(this, arguments);
}
/**
 * 查询国家定义列表的数据
 * @param {Object} params - 查询参数
 * @param {String} params.page - 页码
 * @param {String} params.size - 页数
 */

function _queryProvinceCity() {
  _queryProvinceCity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(countryId) {
    var organizationId;
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            return _context6.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/countries/").concat(countryId, "/regions"), {
              method: 'GET',
              query: {
                enabledFlag: 1
              }
            }));

          case 2:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _queryProvinceCity.apply(this, arguments);
}

export function fetchCountryList() {
  return _fetchCountryList.apply(this, arguments);
}

function _fetchCountryList() {
  _fetchCountryList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
    var organizationId;
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            return _context7.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1").concat(isTenantRoleLevel() ? "/".concat(organizationId) : "", "/countries/all"), {
              method: 'GET',
              query: {
                enabledFlag: 1
              }
            }));

          case 2:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _fetchCountryList.apply(this, arguments);
}